/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 08
 * Time: 14:41
 */
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入开始日期：");
        String beginDay = scanner.nextLine();
        System.out.println("请输入结束日期：");
        String endDay = scanner.nextLine();
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("111111");

        Connection connection = dataSource.getConnection();

        String sql = "insert into borrow_info values(19, 10, 3, ?, ?)";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1, beginDay);
        statement.setString(2, endDay);
        System.out.println("sql = " + statement);

        int n = statement.executeUpdate();
        System.out.println("n = " + n);

        statement.close();
        connection.close();
    }
}

